<?php


namespace app\common\model;


use catcher\exceptions\ValidateFailedException;
use MongoDB\BSON\ObjectId;

class DiseasePath extends BaseModel
{
    protected $name = 'disease_path';

    public function setStepsAttr($value, $data)
    {
        foreach ($value as $k => &$v) {

            if (!isset($v["step_id"])) {
                $v["step_id"] = new ObjectId();
            } else {
                $v["step_id"] = new ObjectId($v["step_id"]['$oid']);
            }
            $v["step_order"] = ($k + 1);
            $v["step_task_title"] = ($k + 1) . "节点 ";
        }
        return $value;
    }


    /**
     * 获取列表
     * @param array $where 查询条件
     * @param string $field 字段
     */
    public function getLists(array $where = [], string $field = "*")
    {
        return $this->mongoSearch()
            ->where($where)
            ->field($field)
            ->order('_id', 'desc')
            ->paginate($this->pageLimit);
    }

    public function getDiseasePathById(string $id)
    {
        return $this->where("id", "=", $id)->find();
    }


}